<template>
  <a-layout-header class="app-header">
    <div class="header-content">
      <div class="logo">
        <span>{{ appStore.appName }}</span>
        <a-tag :color="appStore.isQiankun ? 'blue' : 'green'" style="margin-left: 8px;">
          {{ appStore.isQiankun ? '微应用' : '独立应用' }}
        </a-tag>
      </div>
      
      <a-menu
        v-model:selectedKeys="selectedKeys"
        theme="dark"
        mode="horizontal"
        :style="{ lineHeight: '64px' }"
      >
        <a-menu-item key="home">
          <router-link to="/">
            <HomeOutlined />
            首页
          </router-link>
        </a-menu-item>
        <a-menu-item key="about">
          <router-link to="/about">
            <InfoCircleOutlined />
            关于
          </router-link>
        </a-menu-item>
      </a-menu>
      
      <div class="header-actions">
        <a-space>
          <a-badge :count="appStore.visitCount" :show-zero="false">
            <a-button type="text" @click="showVisitInfo">
              <EyeOutlined />
            </a-button>
          </a-badge>
          <a-button type="text" @click="refreshApp">
            <ReloadOutlined />
          </a-button>
        </a-space>
      </div>
    </div>
  </a-layout-header>
</template>

<script setup>
import { ref, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useAppStore } from '@/stores/app'
import { message } from 'ant-design-vue'
import { 
  HomeOutlined, 
  InfoCircleOutlined, 
  EyeOutlined, 
  ReloadOutlined 
} from '@ant-design/icons-vue'

const route = useRoute()
const appStore = useAppStore()

// 响应式数据
const selectedKeys = ref(['home'])

// 监听路由变化，更新选中的菜单项
watch(() => route.path, (newPath) => {
  if (newPath === '/') {
    selectedKeys.value = ['home']
  } else if (newPath === '/about') {
    selectedKeys.value = ['about']
  }
}, { immediate: true })

// 方法
const showVisitInfo = () => {
  message.info(`当前访问次数: ${appStore.visitCount}`)
}

const refreshApp = () => {
  window.location.reload()
}
</script>

<style lang="scss" scoped>
.app-header {
  .header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    
    .logo {
      color: white;
      font-size: 18px;
      font-weight: bold;
      display: flex;
      align-items: center;
    }
    
    .ant-menu {
      flex: 1;
      justify-content: center;
    }
    
    .header-actions {
      display: flex;
      align-items: center;
      
      .ant-btn {
        color: white;
        
        &:hover {
          color: #1890ff;
        }
      }
    }
  }
}
</style> 